<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品展示</title>
</head>
<style>
    #id1{
width:248px;
height:248px;
}
img{
display:block;
float:left;
margin-left:0px;
width:40px;
height:40px;
padding:5px;
border:1px solid #CCC;
}
</style>
</head>
<body>
<div style="width:300px; margin:5% auto">
<img id="id1" src="img/g1.jpg"><br>

<img src="img/g1.jpg">
<img src="img/g2.jpg">
<img src="img/g3.jpg">
<img src="img/g4.jpg">
<img src="img/g5.jpg">
<div>
</body>
<script type="text/javascript">
var imgg=document.getElementsByTagName("img");
for(var i=1;i<imgg.length;i++){
imgg[i].onmouseover=function(){
var a=this.src;
var i=a.indexOf(".");
var x=a.substr(0,i);
document.getElementById("id1").src=x+".jpg";

imgg[i].onmouseout=function(){
document.getElementById("id1").src="img/g1.jpg";
this.style.border="1px solid #CCC";
}
}
}
</script>
</body>

</html>